package com.velvetantler.weather.view.home

import android.content.Context
import com.qweather.sdk.response.weather.WeatherHourlyResponse
import com.qweather.sdk.response.weather.WeatherNowResponse
import com.velvetantler.weather.base.BasePresenter
import com.velvetantler.weather.bean.CityInfo

class HomePresenter(val homeView: HomeView, val homeModel: HomeModel) :
    BasePresenter<HomeView, HomeModel>(homeView, homeModel) {

    /**
     * 获取实时天气成功回调
     */
    val onWeatherNowDataSucceed: (WeatherNowResponse) -> Unit = {
        homeView.getWeatherNowDataSucceed(it)
    }

    /**
     * 获取实时天气失败回调
     */
    val onWeatherNowDataFailed: (String) -> Unit = {
        homeView.getWeatherNowDataFailed(it)
    }

    /**
     * 获取未来24小时天气成功回调
     */
    val onWeatherHourlyDataSucceed: (WeatherHourlyResponse) -> Unit = {
        homeView.getWeatherHourlyDataSucceed(it)
    }

    /**
     * 获取未来24小时天气失败回调
     */
    val onWeatherHourlyDataFailed: (String) -> Unit = {
        homeView.getWeatherHourlyDataFailed(it)
    }

    /**
     * 获取城市列表成功
     */
    val onCityListDataSucceed: (List<CityInfo>) -> Unit = {
        homeView.getCityListDataSucceed(it)
    }

    /**
     * 获取城市列表失败
     */
    val onCityListDataFailed: (String) -> Unit = {
        homeView.getCityListDataFailed(it)
    }

    /**
     * 获取实时天气
     *
     * @param longitude 经度
     * @param latitude 纬度
     */
    fun requestWeatherNowData(longitude: String, latitude: String) {
        homeModel.requestWeatherNowData(
            longitude,
            latitude,
            onWeatherNowDataSucceed,
            onWeatherNowDataFailed
        )
    }

    /**
     * 获取未来24小时天气
     *
     * @param longitude 经度
     * @param latitude 纬度
     */
    fun requestWeatherHourlyData(longitude: String, latitude: String) {
        homeModel.requestWeatherHourlyData(
            longitude,
            latitude,
            onWeatherHourlyDataSucceed,
            onWeatherHourlyDataFailed
        )
    }

    /**
     * 获取城市列表
     */
    fun requestCityListData(context: Context) {
        homeModel.requestCityListData(context, onCityListDataSucceed, onCityListDataFailed)
    }
}